module Utilities
    import Printf
    function saveMatrix(a::Matrix{Float64},fileName::String; sep::String=" ")
        # save matrix a in a file fileName
        # numbers are seprated by sep
        # sep is double space by default
        row, col = size(a)
        io = open(fileName,"w")
        for r = 1:row
            for c = 1:col
                if c != col
                    write(io, Printf.@sprintf("%.15e%s", a[r,c], sep))
                else
                    write(io, Printf.@sprintf("%.15e", a[r,c]))
                end
            end
            
            if r != row write(io, "\n") end
        end
        
        close(io)
    end
    # a = rand(5,6)
    # saveMatrix(a, "a.txt", sep="\t")

    function readData(fileName::String; dtype=Float64)
        io = open(fileName, "r")
        s = readlines(io)
        cols = length(parse.(dtype, split(s[1], [',', ' ', '\t']; keepempty = false)))
        rows = length(s)
        data = zeros(dtype, rows, cols)
        for (row, num) in enumerate(s)
            data[row, :] = parse.(dtype, split(num, [',', ' ', '\t']; keepempty = false))
        end
        close(io)
        return data
    end

end # end module

# pwd() in LOAD_PATH ? nothing : push!(LOAD_PATH, pwd())
# import .Utilities
# gnum = Utilities.readData("elements.dat",  dtype=Int64)
# gcoord = Utilities.readData("nodes.dat", dtype=Float64)